package com.neolix.watch.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.Adapter;
import android.widget.BaseAdapter;

import org.jetbrains.annotations.Nullable;

public abstract class NeolixBaseAdapter<TView extends View> extends BaseAdapter {
    public static final int NO_SELECTION = Adapter.NO_SELECTION;
    private int selectedPosition = NO_SELECTION;
    private AbsListView listView;

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Nullable
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TView view;

        if (convertView == null)
            view = buildView(parent);
        else
            view = (TView) convertView;

        updateView(view, position);

        return view;
    }

    protected abstract void updateView(TView view, int position);

    protected abstract TView buildView(ViewGroup parent);

    public void bindListView(AbsListView listView) {
        this.listView = listView;
        listView.setAdapter(this);
    }

    public AbsListView getListView() {
        return listView;
    }
}
